package com.example.apple.myrecyclewiew.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.apple.myrecyclewiew.bean.ArticleBean;
import com.example.apple.myrecyclewiew.R;
import com.example.apple.myrecyclewiew.adapter.MyAdapter;
import com.example.apple.myrecyclewiew.iface.ArticleListener;
import com.example.apple.myrecyclewiew.model.ArticleModel;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    List<ArticleBean> list ;
    ArticleListener articleListener = new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> listbean) {
            list = listbean;
            myAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,"fall:"+msg,Toast.LENGTH_SHORT).show();

        }

    };




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        ArticleModel articleModel =new ArticleModel();
        articleModel.getResultList("article",2,"8soafn3tpaj0efuab5jvmpbhr4",articleListener);
        private void init(){


        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);

        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
        ArticleModel articleModel =new ArticleModel();
        articleModel.getResultList("article",2,"8soafn3tpaj0efuab5jvmpbhr4",articleListener);

    }

}
